﻿using System.Windows;
using System.ComponentModel;

namespace DeepEarth.Map.Core
{
    [TypeConverter(typeof(Converters.PositionOriginTypeConverter))]
    public struct PositionOrigin
    {
        public double X { get; set; }
        public double Y { get; set; }

        #region Straight out of Reflector

        public static readonly PositionOrigin TopLeft;
        public static readonly PositionOrigin TopCenter;
        public static readonly PositionOrigin TopRight;
        public static readonly PositionOrigin CenterLeft;
        public static readonly PositionOrigin Center;
        public static readonly PositionOrigin CenterRight;
        public static readonly PositionOrigin BottomLeft;
        public static readonly PositionOrigin BottomCenter;
        public static readonly PositionOrigin BottomRight;

        static PositionOrigin()
        {
            TopLeft = new PositionOrigin(0.0, 0.0);
            TopCenter = new PositionOrigin(0.5, 0.0);
            TopRight = new PositionOrigin(1.0, 0.0);
            CenterLeft = new PositionOrigin(0.0, 0.5);
            Center = new PositionOrigin(0.5, 0.5);
            CenterRight = new PositionOrigin(1.0, 0.5);
            BottomLeft = new PositionOrigin(0.0, 1.0);
            BottomCenter = new PositionOrigin(0.5, 1.0);
            BottomRight = new PositionOrigin(1.0, 1.0);
        }

        #endregion

        public PositionOrigin(double x, double y) : this()
        {
            X = x;
            Y = y;
        }

        public static implicit operator Point(PositionOrigin p)
        {
            return new Point
            {
                X = p.X,
                Y = p.Y
            };
        }

        public static implicit operator PositionOrigin(Point p)
        {
            return new PositionOrigin
            {
                X = p.X,
                Y = p.Y
            };
        }

        public static bool operator ==(PositionOrigin a, PositionOrigin b)
        {
            return a.X == b.X && a.Y == b.Y;
        }

        public static bool operator !=(PositionOrigin a, PositionOrigin b)
        {
            return a.X != b.X || a.Y != b.Y;
        }
    }
}
